package com.batdream.message;

import com.batdream.message.netty.MessageServer;
import com.batdream.message.utils.TimeUtil;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.stereotype.Component;

/**
 * @author Wang Chen Peng
 * @date 2018/12/25
 * describe:
 */
@Component
public class MessageServerInit implements ApplicationListener<ContextRefreshedEvent> {

    @Override
    public void onApplicationEvent(ContextRefreshedEvent contextRefreshedEvent) {
        //root application context 没有parent，他就是老大.
        if (contextRefreshedEvent.getApplicationContext().getParent() == null) {
            System.out.println(TimeUtil.getTime()+"  开始启动 MessageServer");
            try {
                MessageServer.getInstance().start();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
}
